home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / VIDEO / FBCON.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  16KB  |  514 lines

  1. /*
  2.  *  linux/drivers/video/fbcon.h -- Low level frame buffer based console driver
  3.  *
  4.  *    Copyright (C) 1997 Geert Uytterhoeven
  5.  *
  6.  *  This file is subject to the terms and conditions of the GNU General Public
  7.  *  License.  See the file COPYING in the main directory of this archive
  8.  *  for more details.
  9.  */
  10.  
  11. #ifndef _VIDEO_FBCON_H
  12. #define _VIDEO_FBCON_H
  13.  
  14. #include <linux/config.h>
  15. #include <linux/console_struct.h>
  16. #include <linux/vt_buffer.h>
  17.  
  18.  
  19.     /*                                  
  20.      *  `switch' for the Low Level Operations
  21.      */
  22.  
  23. struct display_switch {                                                
  24.     void (*setup)(struct display *p);
  25.     void (*bmove)(struct display *p, int sy, int sx, int dy, int dx,
  26.           int height, int width);
  27.     /* for clear, conp may be NULL, which means use a blanking (black) color */
  28.     void (*clear)(struct vc_data *conp, struct display *p, int sy, int sx,
  29.           int height, int width);
  30.     void (*putc)(struct vc_data *conp, struct display *p, int c, int yy,
  31.              int xx);
  32.     void (*putcs)(struct vc_data *conp, struct display *p, const unsigned short *s,
  33.           int count, int yy, int xx);     
  34.     void (*revc)(struct display *p, int xx, int yy);
  35.     void (*cursor)(struct display *p, int mode, int xx, int yy);
  36.     int  (*set_font)(struct display *p, int width, int height);
  37.     void (*clear_margins)(struct vc_data *conp, struct display *p,
  38.               int bottom_only);
  39.     unsigned int fontwidthmask;      /* 1 at (1 << (width - 1)) if width is supported */
  40. }; 
  41.  
  42. extern struct display_switch fbcon_dummy;
  43.  
  44. #define fontheight(p) ((p)->_fontheight)
  45. #define fontheightlog(p) ((p)->_fontheightlog)
  46.  
  47. #ifdef CONFIG_FBCON_FONTWIDTH8_ONLY
  48.  
  49. /* fontwidth w is supported by dispsw */
  50. #define FONTWIDTH(w)    (1 << ((8) - 1))
  51. /* fontwidths w1-w2 inclusive are supported by dispsw */
  52. #define FONTWIDTHRANGE(w1,w2)    FONTWIDTH(8)
  53.  
  54. #define fontwidth(p) (8)
  55. #define fontwidthlog(p) (0)
  56.  
  57. #else
  58.  
  59. /* fontwidth w is supported by dispsw */
  60. #define FONTWIDTH(w)    (1 << ((w) - 1))
  61. /* fontwidths w1-w2 inclusive are supported by dispsw */
  62. #define FONTWIDTHRANGE(w1,w2)    (FONTWIDTH(w2+1) - FONTWIDTH(w1))
  63.  
  64. #define fontwidth(p) ((p)->_fontwidth)
  65. #define fontwidthlog(p) ((p)->_fontwidthlog)
  66.  
  67. #endif
  68.  
  69.     /*
  70.      *  Attribute Decoding
  71.      */
  72.  
  73. /* Color */
  74. #define attr_fgcol(p,s)    \
  75.     (((s) >> ((p)->fgshift)) & 0x0f)
  76. #define attr_bgcol(p,s)    \
  77.     (((s) >> ((p)->bgshift)) & 0x0f)
  78. #define    attr_bgcol_ec(p,conp) \
  79.     ((conp) ? (((conp)->vc_video_erase_char >> ((p)->bgshift)) & 0x0f) : 0)
  80.  
  81. /* Monochrome */
  82. #define attr_bold(p,s) \
  83.     ((s) & 0x200)
  84. #define attr_reverse(p,s) \
  85.     (((s) & 0x800) ^ ((p)->inverse ? 0x800 : 0))
  86. #define attr_underline(p,s) \
  87.     ((s) & 0x400)
  88. #define attr_blink(p,s) \
  89.     ((s) & 0x8000)
  90.     
  91.     /*
  92.      *  Scroll Method
  93.      */
  94.      
  95. /* Internal flags */
  96. #define __SCROLL_YPAN        0x001
  97. #define __SCROLL_YWRAP        0x002
  98. #define __SCROLL_YMOVE        0x003
  99. #define __SCROLL_YREDRAW    0x004
  100. #define __SCROLL_YMASK        0x00f
  101. #define __SCROLL_YFIXED        0x010
  102. #define __SCROLL_YNOMOVE    0x020
  103. #define __SCROLL_YPANREDRAW    0x040
  104. #define __SCROLL_YNOPARTIAL    0x080
  105.  
  106. /* Only these should be used by the drivers */
  107. /* Which one should you use? If you have a fast card and slow bus,
  108.    then probably just 0 to indicate fbcon should choose between
  109.    YWRAP/YPAN+MOVE/YMOVE. On the other side, if you have a fast bus
  110.    and even better if your card can do fonting (1->8/32bit painting),
  111.    you should consider either SCROLL_YREDRAW (if your card is
  112.    able to do neither YPAN/YWRAP), or SCROLL_YNOMOVE.
  113.    The best is to test it with some real life scrolling (usually, not
  114.    all lines on the screen are filled completely with non-space characters,
  115.    and REDRAW performs much better on such lines, so don't cat a file
  116.    with every line covering all screen columns, it would not be the right
  117.    benchmark).
  118.  */
  119. #define SCROLL_YREDRAW        (__SCROLL_YFIXED|__SCROLL_YREDRAW)
  120. #define SCROLL_YNOMOVE        (__SCROLL_YNOMOVE|__SCROLL_YPANREDRAW)
  121.  
  122. /* SCROLL_YNOPARTIAL, used in combination with the above, is for video
  123.    cards which can not handle using panning to scroll a portion of the
  124.    screen without excessive flicker.  Panning will only be used for
  125.    whole screens.
  126.  */
  127. /* Namespace consistency */
  128. #define SCROLL_YNOPARTIAL    __SCROLL_YNOPARTIAL
  129.  
  130.  
  131. extern void fbcon_redraw_bmove(struct display *, int, int, int, int, int, int);
  132.  
  133.  
  134. /* ================================================================= */
  135. /*                      Utility Assembler Functions                  */
  136. /* ================================================================= */
  137.  
  138.  
  139. #if defined(__mc68000__)
  140.  
  141. /* ====================================================================== */
  142.  
  143. /* Those of a delicate disposition might like to skip the next couple of
  144.  * pages.
  145.  *
  146.  * These functions are drop in replacements for memmove and
  147.  * memset(_, 0, _). However their five instances add at least a kilobyte
  148.  * to the object file. You have been warned.
  149.  *
  150.  * Not a great fan of assembler for the sake of it, but I think
  151.  * that these routines are at least 10 times faster than their C
  152.  * equivalents for large blits, and that's important to the lowest level of
  153.  * a graphics driver. Question is whether some scheme with the blitter
  154.  * would be faster. I suspect not for simple text system - not much
  155.  * asynchrony.
  156.  *
  157.  * Code is very simple, just gruesome expansion. Basic strategy is to
  158.  * increase data moved/cleared at each step to 16 bytes to reduce
  159.  * instruction per data move overhead. movem might be faster still
  160.  * For more than 15 bytes, we try to align the write direction on a
  161.  * longword boundary to get maximum speed. This is even more gruesome.
  162.  * Unaligned read/write used requires 68020+ - think this is a problem?
  163.  *
  164.  * Sorry!
  165.  */
  166.  
  167.  
  168. /* ++roman: I've optimized Robert's original versions in some minor
  169.  * aspects, e.g. moveq instead of movel, let gcc choose the registers,
  170.  * use movem in some places...
  171.  * For other modes than 1 plane, lots of more such assembler functions
  172.  * were needed (e.g. the ones using movep or expanding color values).
  173.  */
  174.  
  175. /* ++andreas: more optimizations:
  176.    subl #65536,d0 replaced by clrw d0; subql #1,d0 for dbcc
  177.    addal is faster than addaw
  178.    movep is rather expensive compared to ordinary move's
  179.    some functions rewritten in C for clarity, no speed loss */
  180.  
  181. static __inline__ void *mymemclear_small(void *s, size_t count)
  182. {
  183.    if (!count)
  184.       return(0);
  185.  
  186.    __asm__ __volatile__(
  187.          "lsrl   #1,%1 ; jcc 1f ; moveb %2,%0@-\n\t"
  188.       "1: lsrl   #1,%1 ; jcc 1f ; movew %2,%0@-\n\t"
  189.       "1: lsrl   #1,%1 ; jcc 1f ; movel %2,%0@-\n\t"
  190.       "1: lsrl   #1,%1 ; jcc 1f ; movel %2,%0@- ; movel %2,%0@-\n\t"
  191.       "1: subql  #1,%1 ; jcs 3f\n\t"
  192.       "2: moveml %2/%3/%4/%5,%0@-\n\t"
  193.          "dbra %1,2b\n\t"
  194.       "3:"
  195.          : "=a" (s), "=d" (count)
  196.          :  "d" (0), "d" (0), "d" (0), "d" (0),
  197.             "0" ((char *)s+count), "1" (count)
  198.   );
  199.  
  200.    return(0);
  201. }
  202.  
  203.  
  204. static __inline__ void *mymemclear(void *s, size_t count)
  205. {
  206.    if (!count)
  207.       return(0);
  208.  
  209.    if (count < 16) {
  210.       __asm__ __volatile__(
  211.             "lsrl   #1,%1 ; jcc 1f ; clrb %0@+\n\t"
  212.          "1: lsrl   #1,%1 ; jcc 1f ; clrw %0@+\n\t"
  213.          "1: lsrl   #1,%1 ; jcc 1f ; clrl %0@+\n\t"
  214.          "1: lsrl   #1,%1 ; jcc 1f ; clrl %0@+ ; clrl %0@+\n\t"
  215.          "1:"
  216.             : "=a" (s), "=d" (count)
  217.             : "0" (s), "1" (count)
  218.      );
  219.    } else {
  220.       long tmp;
  221.       __asm__ __volatile__(
  222.             "movel %1,%2\n\t"
  223.             "lsrl   #1,%2 ; jcc 1f ; clrb %0@+ ; subqw #1,%1\n\t"
  224.             "lsrl   #1,%2 ; jcs 2f\n\t"  /* %0 increased=>bit 2 switched*/
  225.             "clrw   %0@+  ; subqw  #2,%1 ; jra 2f\n\t"
  226.          "1: lsrl   #1,%2 ; jcc 2f\n\t"
  227.             "clrw   %0@+  ; subqw  #2,%1\n\t"
  228.          "2: movew %1,%2; lsrl #2,%1 ; jeq 6f\n\t"
  229.             "lsrl   #1,%1 ; jcc 3f ; clrl %0@+\n\t"
  230.          "3: lsrl   #1,%1 ; jcc 4f ; clrl %0@+ ; clrl %0@+\n\t"
  231.          "4: subql  #1,%1 ; jcs 6f\n\t"
  232.          "5: clrl %0@+; clrl %0@+ ; clrl %0@+ ; clrl %0@+\n\t"
  233.             "dbra %1,5b   ; clrw %1; subql #1,%1; jcc 5b\n\t"
  234.          "6: movew %2,%1; btst #1,%1 ; jeq 7f ; clrw %0@+\n\t"
  235.          "7:            ; btst #0,%1 ; jeq 8f ; clrb %0@+\n\t"
  236.          "8:"
  237.             : "=a" (s), "=d" (count), "=d" (tmp)
  238.             : "0" (s), "1" (count)
  239.      );
  240.    }
  241.  
  242.    return(0);
  243. }
  244.  
  245.  
  246. static __inline__ void *mymemset(void *s, size_t count)
  247. {
  248.    if (!count)
  249.       return(0);
  250.  
  251.    __asm__ __volatile__(
  252.          "lsrl   #1,%1 ; jcc 1f ; moveb %2,%0@-\n\t"
  253.       "1: lsrl   #1,%1 ; jcc 1f ; movew %2,%0@-\n\t"
  254.       "1: lsrl   #1,%1 ; jcc 1f ; movel %2,%0@-\n\t"
  255.       "1: lsrl   #1,%1 ; jcc 1f ; movel %2,%0@- ; movel %2,%0@-\n\t"
  256.       "1: subql  #1,%1 ; jcs 3f\n\t"
  257.       "2: moveml %2/%3/%4/%5,%0@-\n\t"
  258.          "dbra %1,2b\n\t"
  259.       "3:"
  260.          : "=a" (s), "=d" (count)
  261.          :  "d" (-1), "d" (-1), "d" (-1), "d" (-1),
  262.             "0" ((char *) s + count), "1" (count)
  263.   );
  264.  
  265.    return(0);
  266. }
  267.  
  268.  
  269. static __inline__ void *mymemmove(void *d, const void *s, size_t count)
  270. {
  271.    if (d < s) {
  272.       if (count < 16) {
  273.          __asm__ __volatile__(
  274.                "lsrl   #1,%2 ; jcc 1f ; moveb %1@+,%0@+\n\t"
  275.             "1: lsrl   #1,%2 ; jcc 1f ; movew %1@+,%0@+\n\t"
  276.             "1: lsrl   #1,%2 ; jcc 1f ; movel %1@+,%0@+\n\t"
  277.             "1: lsrl   #1,%2 ; jcc 1f ; movel %1@+,%0@+ ; movel %1@+,%0@+\n\t"
  278.             "1:"
  279.                : "=a" (d), "=a" (s), "=d" (count)
  280.                : "0" (d), "1" (s), "2" (count)
  281.         );
  282.       } else {
  283.          long tmp;
  284.          __asm__ __volatile__(
  285.                "movel  %0,%3\n\t"
  286.                "lsrl   #1,%3 ; jcc 1f ; moveb %1@+,%0@+ ; subqw #1,%2\n\t"
  287.                "lsrl   #1,%3 ; jcs 2f\n\t"  /* %0 increased=>bit 2 switched*/
  288.                "movew  %1@+,%0@+  ; subqw  #2,%2 ; jra 2f\n\t"
  289.             "1: lsrl   #1,%3 ; jcc 2f\n\t"
  290.                "movew  %1@+,%0@+  ; subqw  #2,%2\n\t"
  291.             "2: movew  %2,%-; lsrl #2,%2 ; jeq 6f\n\t"
  292.                "lsrl   #1,%2 ; jcc 3f ; movel %1@+,%0@+\n\t"
  293.             "3: lsrl   #1,%2 ; jcc 4f ; movel %1@+,%0@+ ; movel %1@+,%0@+\n\t"
  294.             "4: subql  #1,%2 ; jcs 6f\n\t"
  295.             "5: movel  %1@+,%0@+;movel %1@+,%0@+\n\t"
  296.                "movel  %1@+,%0@+;movel %1@+,%0@+\n\t"
  297.                "dbra   %2,5b ; clrw %2; subql #1,%2; jcc 5b\n\t"
  298.             "6: movew  %+,%2; btst #1,%2 ; jeq 7f ; movew %1@+,%0@+\n\t"
  299.             "7:              ; btst #0,%2 ; jeq 8f ; moveb %1@+,%0@+\n\t"
  300.             "8:"
  301.                : "=a" (d), "=a" (s), "=d" (count), "=d" (tmp)
  302.                : "0" (d), "1" (s), "2" (count)
  303.         );
  304.       }
  305.    } else {
  306.       if (count < 16) {
  307.          __asm__ __volatile__(
  308.                "lsrl   #1,%2 ; jcc 1f ; moveb %1@-,%0@-\n\t"
  309.             "1: lsrl   #1,%2 ; jcc 1f ; movew %1@-,%0@-\n\t"
  310.             "1: lsrl   #1,%2 ; jcc 1f ; movel %1@-,%0@-\n\t"
  311.             "1: lsrl   #1,%2 ; jcc 1f ; movel %1@-,%0@- ; movel %1@-,%0@-\n\t"
  312.             "1:"
  313.                : "=a" (d), "=a" (s), "=d" (count)
  314.                : "0" ((char *) d + count), "1" ((char *) s + count), "2" (count)
  315.         );
  316.       } else {
  317.          long tmp;
  318.          __asm__ __volatile__(
  319.                "movel %0,%3\n\t"
  320.                "lsrl   #1,%3 ; jcc 1f ; moveb %1@-,%0@- ; subqw #1,%2\n\t"
  321.                "lsrl   #1,%3 ; jcs 2f\n\t"  /* %0 increased=>bit 2 switched*/
  322.                "movew  %1@-,%0@-  ; subqw  #2,%2 ; jra 2f\n\t"
  323.             "1: lsrl   #1,%3 ; jcc 2f\n\t"
  324.                "movew  %1@-,%0@-  ; subqw  #2,%2\n\t"
  325.             "2: movew %2,%-; lsrl #2,%2 ; jeq 6f\n\t"
  326.                "lsrl   #1,%2 ; jcc 3f ; movel %1@-,%0@-\n\t"
  327.             "3: lsrl   #1,%2 ; jcc 4f ; movel %1@-,%0@- ; movel %1@-,%0@-\n\t"
  328.             "4: subql  #1,%2 ; jcs 6f\n\t"
  329.             "5: movel %1@-,%0@-;movel %1@-,%0@-\n\t"
  330.                "movel %1@-,%0@-;movel %1@-,%0@-\n\t"
  331.                "dbra %2,5b ; clrw %2; subql #1,%2; jcc 5b\n\t"
  332.             "6: movew %+,%2; btst #1,%2 ; jeq 7f ; movew %1@-,%0@-\n\t"
  333.             "7:              ; btst #0,%2 ; jeq 8f ; moveb %1@-,%0@-\n\t"
  334.             "8:"
  335.                : "=a" (d), "=a" (s), "=d" (count), "=d" (tmp)
  336.                : "0" ((char *) d + count), "1" ((char *) s + count), "2" (count)
  337.         );
  338.       }
  339.    }
  340.  
  341.    return(0);
  342. }
  343.  
  344.  
  345. /* ++andreas: Simple and fast version of memmove, assumes size is
  346.    divisible by 16, suitable for moving the whole screen bitplane */
  347. static __inline__ void fast_memmove(char *dst, const char *src, size_t size)
  348. {
  349.   if (!size)
  350.     return;
  351.   if (dst < src)
  352.     __asm__ __volatile__
  353.       ("1:"
  354.        "  moveml %0@+,%/d0/%/d1/%/a0/%/a1\n"
  355.        "  moveml %/d0/%/d1/%/a0/%/a1,%1@\n"
  356.        "  addql #8,%1; addql #8,%1\n"
  357.        "  dbra %2,1b\n"
  358.        "  clrw %2; subql #1,%2\n"
  359.        "  jcc 1b"
  360.        : "=a" (src), "=a" (dst), "=d" (size)
  361.        : "0" (src), "1" (dst), "2" (size / 16 - 1)
  362.        : "d0", "d1", "a0", "a1", "memory");
  363.   else
  364.     __asm__ __volatile__
  365.       ("1:"
  366.        "  subql #8,%0; subql #8,%0\n"
  367.        "  moveml %0@,%/d0/%/d1/%/a0/%/a1\n"
  368.        "  moveml %/d0/%/d1/%/a0/%/a1,%1@-\n"
  369.        "  dbra %2,1b\n"
  370.        "  clrw %2; subql #1,%2\n"
  371.        "  jcc 1b"
  372.        : "=a" (src), "=a" (dst), "=d" (size)
  373.        : "0" (src + size), "1" (dst + size), "2" (size / 16 - 1)
  374.        : "d0", "d1", "a0", "a1", "memory");
  375. }
  376.  
  377. #elif defined(CONFIG_SUN4)
  378.  
  379. /* You may think that I'm crazy and that I should use generic
  380.    routines.  No, I'm not: sun4's framebuffer crashes if we std
  381.    into it, so we cannot use memset.  */
  382.  
  383. static __inline__ void *sun4_memset(void *s, char val, size_t count)
  384. {
  385.     int i;
  386.     for(i=0; i<count;i++)
  387.         ((char *) s) [i] = val;
  388.     return s;
  389. }
  390.  
  391. static __inline__ void *mymemset(void *s, size_t count)
  392. {
  393.     return sun4_memset(s, 255, count);
  394. }
  395.  
  396. static __inline__ void *mymemclear(void *s, size_t count)
  397. {
  398.     return sun4_memset(s, 0, count);
  399. }
  400.  
  401. static __inline__ void *mymemclear_small(void *s, size_t count)
  402. {
  403.     return sun4_memset(s, 0, count);
  404. }
  405.  
  406. /* To be honest, this is slow_memmove :). But sun4 is crappy, so what we can do. */
  407. static __inline__ void fast_memmove(void *d, const void *s, size_t count)
  408. {
  409.     int i;
  410.     if (d<s) {
  411.     for (i=0; i<count; i++)
  412.         ((char *) d)[i] = ((char *) s)[i];
  413.     } else
  414.     for (i=0; i<count; i++)
  415.         ((char *) d)[count-i-1] = ((char *) s)[count-i-1];
  416. }
  417.  
  418. static __inline__ void *mymemmove(char *dst, const char *src, size_t size)
  419. {
  420.     fast_memmove(dst, src, size);
  421.     return dst;
  422. }
  423.  
  424. #else
  425.  
  426. static __inline__ void *mymemclear_small(void *s, size_t count)
  427. {
  428.     return(memset(s, 0, count));
  429. }
  430.  
  431. static __inline__ void *mymemclear(void *s, size_t count)
  432. {
  433.     return(memset(s, 0, count));
  434. }
  435.  
  436. static __inline__ void *mymemset(void *s, size_t count)
  437. {
  438.     return(memset(s, 255, count));
  439. }
  440.  
  441. #if defined(__i386__)
  442.  
  443. static __inline__ void fast_memmove(void *d, const void *s, size_t count)
  444. {
  445.   int d0, d1, d2, d3;
  446.     if (d < s) {
  447. __asm__ __volatile__ (
  448.     "cld\n\t"
  449.     "shrl $1,%%ecx\n\t"
  450.     "jnc 1f\n\t"
  451.     "movsb\n"
  452.     "1:\tshrl $1,%%ecx\n\t"
  453.     "jnc 2f\n\t"
  454.     "movsw\n"
  455.     "2:\trep\n\t"
  456.     "movsl"
  457.     : "=&c" (d0), "=&D" (d1), "=&S" (d2)
  458.     :"0"(count),"1"((long)d),"2"((long)s)
  459.     :"memory");
  460.     } else {
  461. __asm__ __volatile__ (
  462.     "std\n\t"
  463.     "shrl $1,%%ecx\n\t"
  464.     "jnc 1f\n\t"
  465.     "movb 3(%%esi),%%al\n\t"
  466.     "movb %%al,3(%%edi)\n\t"
  467.     "decl %%esi\n\t"
  468.     "decl %%edi\n"
  469.     "1:\tshrl $1,%%ecx\n\t"
  470.     "jnc 2f\n\t"
  471.     "movw 2(%%esi),%%ax\n\t"
  472.     "movw %%ax,2(%%edi)\n\t"
  473.     "decl %%esi\n\t"
  474.     "decl %%edi\n\t"
  475.     "decl %%esi\n\t"
  476.     "decl %%edi\n"
  477.     "2:\trep\n\t"
  478.     "movsl\n\t"
  479.     "cld"
  480.     : "=&c" (d0), "=&D" (d1), "=&S" (d2), "=&a" (d3)
  481.     :"0"(count),"1"(count-4+(long)d),"2"(count-4+(long)s)
  482.     :"memory");
  483.     }
  484. }
  485.  
  486. static __inline__ void *mymemmove(char *dst, const char *src, size_t size)
  487. {
  488.     fast_memmove(dst, src, size);
  489.     return dst;
  490. }
  491.  
  492. #else /* !i386 */
  493.  
  494.     /*
  495.      *  Anyone who'd like to write asm functions for other CPUs?
  496.      *   (Why are these functions better than those from include/asm/string.h?)
  497.      */
  498.  
  499. static __inline__ void *mymemmove(void *d, const void *s, size_t count)
  500. {
  501.     return(memmove(d, s, count));
  502. }
  503.  
  504. static __inline__ void fast_memmove(char *dst, const char *src, size_t size)
  505. {
  506.     memmove(dst, src, size);
  507. }
  508.  
  509. #endif /* !i386 */
  510.  
  511. #endif
  512.  
  513. #endif /* _VIDEO_FBCON_H */
  514.